﻿using UnityEngine;

public class ButterflyCollisionBehaviour : BaseBehaviour
{
    private ButterflyCollisionManager butterflyCollisionManager;

    protected override void start()
    {
        setUpCollision();
    }

    private void setUpCollision()
    {
        createCollisionManager();
        addBlockCollisionToCollisionManager();
        addObstacleCollisionToCollisionManager();
    }

    private void createCollisionManager()
    {
        butterflyCollisionManager = new ButterflyCollisionManager();
    }

    private void addBlockCollisionToCollisionManager()
    {
        butterflyCollisionManager.add(new ButterflyCollision("Block"));
    }

    private void addObstacleCollisionToCollisionManager()
    {
        butterflyCollisionManager.add(new ButterflyCollision("Obstacle"));
    }  

    private void OnTriggerEnter(Collider otherCollider)
    {
        if (butterflyCollisionManager.hasCollidedWith(otherCollider))
            destroyButterfly();
    }

    private void destroyButterfly()
    {
        GameObjectManager.destroy(gameObject);
    }
}
